home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 194_01 / overstrk.c < prev    next >
Text File  |  1985-11-13  |  2KB  |  101 lines

  1. /* [OVERSTRK.C of JUGPDS Vol.17]
  2. *****************************************************************
  3. *                                *
  4. *    Written by  Hakuo Katayose (JUG-CP/M No.179)        *
  5. *            49-114 Kawauchi-Sanjuunin-machi        *
  6. *            Sendai, Miyagi 980                          *
  7. *            Phone: 0222-61-3219                *
  8. *                                *
  9. *    Edited & tested by Y. Monma (JUG-C/M Disk Editor)       * 
  10. *                                *
  11. *****************************************************************
  12. */
  13.  
  14. /* overstrike - convert backspaces into multiple lines */
  15.  
  16. #include "stdio.h"
  17. #include <dio.h>
  18.  
  19. #define    ON    -1
  20. #define    OFF    0
  21.  
  22. int    cr_flag;
  23.  
  24. main(argc, argv)
  25. int    argc;
  26. char     **argv;
  27.  
  28. {
  29.     FILE    inbuf, *fp;
  30.  
  31.     if (wildexp(&argc,&argv) == ERROR)
  32.         exit(puts("Wildexp overflow"));
  33.     dioinit(&argc, argv);
  34.     cr_flag = OFF;
  35.     if (argc == 1)
  36.         overstrik(STDIN);
  37.     else
  38.         while (--argc > 0)
  39.             if (fopen(*++argv, fp) == 0) {
  40.                 fprintf(STDERR, "Can't open %s\n", *argv);
  41.                 exit(1);
  42.                 }
  43.             else {
  44.                 overstrik(fp);
  45.                 fclose(fp);
  46.                 }
  47.     dioflush();
  48. }
  49.  
  50.  
  51. #define    SKIP    ' '
  52. #define    NOSKIP    '+'
  53. #define    FF    '1'
  54.  
  55. overstrik(fp)
  56. FILE    *fp;
  57. {
  58.     int    c, col, newcol;
  59.  
  60.     for (col = 1; ; col = (c == NEWLINE) ? 1 : col + 1) {
  61.         newcol    = col;
  62.         while ((c = getc(fp)) == BACKSPACE)
  63.             newcol = max(newcol-1, 1);
  64.         if (newcol < col) {
  65.             putch(NEWLINE);
  66.             putch(NOSKIP);
  67.             for (col = 1; col < newcol; col++)
  68.                 putch(BLANK);
  69.         }
  70.         else if (col == 1 && c != EOF && c != CPMEOF)
  71.             putch(SKIP);
  72.         if (c == EOF || c == CPMEOF)
  73.             break;
  74.         putch(c);
  75.     }
  76. }
  77.  
  78.  
  79. putch(c)
  80. {
  81.     if (cr_flag == ON) {
  82.         cr_flag = OFF;
  83.         if (c == NEWLINE) {
  84.             putchar(NEWLINE);
  85.             cr_flag = ON;
  86.         }
  87.         else if (c == NOSKIP)
  88.             putchar(CRETURN);
  89.         else if (c == SKIP)
  90.             putchar(NEWLINE);
  91.         else if (c == FF)
  92.             putchar(FORMFEED);
  93.         else
  94.             putchar(c);
  95.     } else if (c == NEWLINE) {
  96.         putchar(CRETURN);
  97.         cr_flag = ON;
  98.     } else
  99.         putchar(c);
  100. }
  101.